﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace MountainORocks
{
    class ParticleManager
    {
        const int MAX_PARTICLES = 1024;

        Particle[] particles = new Particle[MAX_PARTICLES];
        SpriteBatch spriteBatch;

        public ParticleManager(SpriteBatch spriteBatch)
        {
            this.spriteBatch = spriteBatch;
        }

        public void AddParticle(Particle newParticle)
        {
            for (int i = 0; i < particles.Length; i++)
            {
                if (particles[i] == null)
                {
                    particles[i] = newParticle;
                    break;
                }
            }
        }

        public void UpdateParticles(float frameTime)
        {
            for (int i = 0; i < particles.Length; i++)
            {
                if (particles[i] != null)
                {
                    particles[i].Update(frameTime);
                    if (!particles[i].Exists)
                    {
                        particles[i] = null;
                    }
                }
            }
        }

        public void DrawParticles(Texture2D smokeText,Texture2D shetterText)
        {
            
            foreach (Particle p in particles)
            {
                if (p != null)
                {
                    if (p.myType=="Smoke")
                        p.Draw(spriteBatch, smokeText);
                    if (p.myType=="Shatter")
                        p.Draw(spriteBatch, shetterText);
                }
            }
            
        }

    }
}
